%Figure 3
clear variables

load('Fig3_weather.mat')
%% Figure 3 Panel A

figure
ax = usamap('all');
set(ax, 'Visible', 'off')
states = shaperead('usastatelo', 'UseGeoCoords', true);
names = {states.Name};
indexHawaii = strcmp('Hawaii',names);
indexAlaska = strcmp('Alaska',names);
indexConus = 1:numel(states);
indexConus(indexHawaii|indexAlaska) = []; 

for i=1:numel(states)-1 %fills everything leaving DC for last
    if i<9
        states(i).r=r_observed_1979_2020(i,2,42);
    else
        states(i).r=r_observed_1979_2020(i+1,2,42);
    end
end

states(51).r=r_observed_1979_2020(9,2,42);
 
%hatch marks
hatch=test1(:,3)+test1_10(:,3);

surfaceColors = makesymbolspec('Polygon', {'r', ...
    [-1 1], 'FaceColor', flipud(cmap) });

% Display the three regions.

geoshow(ax(1), states(indexConus),  'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')
geoshow(ax(2), states(indexAlaska), 'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')
geoshow(ax(3), states(indexHawaii), 'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')

%hatching
for i=1:51
    if i~= 2 && i~=12 
        if i<9
        tmp_hp=patchm(states(i).Lat,states(i).Lon,'b','EdgeColor','none','FaceColor','none');
            if hatch(i)==0
                hatchfill2(tmp_hp,'cross','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            elseif hatch(i)==1
                hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            end
        else
        tmp_hp=patchm(states(i-1).Lat,states(i-1).Lon,'b','EdgeColor','none','FaceColor','none');
            if hatch(i)==0
                hatchfill2(tmp_hp,'cross','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            elseif hatch(i)==1
                hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            end       
        end
    end
end


    axes(ax(2))
    tmp_hp=patchm(states(2).Lat,states(2).Lon,'b','EdgeColor','none','FaceColor','none');
    if hatch(2)==0
        hatchfill2(tmp_hp,'cross','HatchAngle',30,'HatchDensity',20,'HatchColor','black','HatchLineWidth',0.5);
    elseif hatch(2)==1
        hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
    end  



    axes(ax(3))
    tmp_hp=patchm(states(11).Lat,states(11).Lon,'b','EdgeColor','none','FaceColor','none');
    if hatch(12)==0
        hatchfill2(tmp_hp,'cross','HatchAngle',45,'HatchDensity',20,'HatchColor','black','HatchLineWidth',0.5);
    elseif hatch(12)==1
                hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',40,'HatchColor','white','HatchLineWidth',0.5);
    end


axes(ax(1))
caxis([-1 1])
colormap(flipud(cmap))

colorbar

%hide the frame
for k = 1:3
    setm(ax(k), 'Frame', 'off', 'Grid', 'off',...
      'ParallelLabel', 'off', 'MeridianLabel', 'off')
end

%% Figure 3 Panel B

figure
nexttile
plot(17, 0, 'r*', 'LineWidth', 2, 'MarkerSize', 10);
hold on
histogram(test1_null_sum(1,3,:))
xlim([-1 18])
ylim([0 20])
xlabel('Number of States with Significant Parks-Temperature Correlations')
ylabel('Number of Years')

%% Figure 3 Panel C

figure
ax = usamap('all');
set(ax, 'Visible', 'off')
states = shaperead('usastatelo', 'UseGeoCoords', true);
names = {states.Name};
indexHawaii = strcmp('Hawaii',names);
indexAlaska = strcmp('Alaska',names);
indexConus = 1:numel(states);
indexConus(indexHawaii|indexAlaska) = []; 

for i=1:numel(states)-1 %fills everything leaving DC for last
    if i<9
        states(i).r=r_observed_1979_2020(i,1,42);
    else
        states(i).r=r_observed_1979_2020(i+1,1,42);
    end
end

states(51).r=r_observed_1979_2020(9,1,42);
 
%hatch marks
hatch=test1(:,1)+test1_10(:,1);

surfaceColors = makesymbolspec('Polygon', {'r', ...
    [-1 1], 'FaceColor', flipud(cmap) });

% Display the three regions.

geoshow(ax(1), states(indexConus),  'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')
geoshow(ax(2), states(indexAlaska), 'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')
geoshow(ax(3), states(indexHawaii), 'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')

%hatching
for i=1:51
    if i~= 2 && i~=12 
        if i<9
        tmp_hp=patchm(states(i).Lat,states(i).Lon,'b','EdgeColor','none','FaceColor','none');
            if hatch(i)==0
                hatchfill2(tmp_hp,'cross','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            elseif hatch(i)==1
                hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            end
        else
        tmp_hp=patchm(states(i-1).Lat,states(i-1).Lon,'b','EdgeColor','none','FaceColor','none');
            if hatch(i)==0
                hatchfill2(tmp_hp,'cross','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            elseif hatch(i)==1
                hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
            end       
        end
    end
end


    axes(ax(2))
    tmp_hp=patchm(states(2).Lat,states(2).Lon,'b','EdgeColor','none','FaceColor','none');
    if hatch(2)==0
        hatchfill2(tmp_hp,'cross','HatchAngle',30,'HatchDensity',20,'HatchColor','black','HatchLineWidth',0.5);
    elseif hatch(2)==1
        hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',40,'HatchColor','black','HatchLineWidth',0.5);
    end  



    axes(ax(3))
    tmp_hp=patchm(states(11).Lat,states(11).Lon,'b','EdgeColor','none','FaceColor','none');
    if hatch(12)==0
        hatchfill2(tmp_hp,'cross','HatchAngle',45,'HatchDensity',20,'HatchColor','black','HatchLineWidth',0.5);
    elseif hatch(12)==1
                hatchfill2(tmp_hp,'single','HatchAngle',45,'HatchDensity',40,'HatchColor','white','HatchLineWidth',0.5);
    end


axes(ax(1))
caxis([-1 1])
colormap(flipud(cmap))

colorbar

%hide the frame
for k = 1:3
    setm(ax(k), 'Frame', 'off', 'Grid', 'off',...
      'ParallelLabel', 'off', 'MeridianLabel', 'off')
end

%% Figure 3 Panel D

figure
plot(1, 0, 'r*', 'LineWidth', 2, 'MarkerSize', 10);
hold on
histogram(test1_null_sum(1,1,:))
xlim([-1 18])
ylim([0 20])
xlabel('Number of States with Significant Encounters-Temperature Correlations')
ylabel('Number of Years')
